#include<bits/stdc++.h>
using namespace std;
const int N=305;
int n;
int a[N];
int f[N][N][N];
int dfs(int l,int r,int be){
    int len=r-l+1;
    if(len==0)return 0;
    if(f[l][r][be]!=0x3f3f3f3f)return f[l][r][be];
    if(a[l]==be)f[l][r][be]=min(f[l][r][be],dfs(l+1,r,be+1));
    else f[l][r][be]=min(f[l][r][be],dfs(l+1,r,be+1)+1);
    if(a[l]==be+len-1)f[l][r][be]=min(f[l][r][be],dfs(l+1,r,be));
    else f[l][r][be]=min(f[l][r][be],dfs(l+1,r,be)+1);
    if(a[r]==be)f[l][r][be]=min(f[l][r][be],dfs(l,r-1,be+1));
    else f[l][r][be]=min(f[l][r][be],dfs(l,r-1,be+1)+1);
    if(a[r]==be+len-1)f[l][r][be]=min(f[l][r][be],dfs(l,r-1,be));
    else f[l][r][be]=min(f[l][r][be],dfs(l,r-1,be)+1);
    return f[l][r][be];
}
int main(){
    freopen("build.in","r",stdin);
    freopen("build.out","w",stdout);
    cin>>n;
    memset(f,0x3f,sizeof(f));
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    cout<<dfs(1,n,1);
    return 0;
}
